<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\supplyDemand\model;

use app\cassification\model\ClassificationDictionary;
use app\enterpriseContact\model\enterpriseContact;
use plugin\saiadmin\basic\BaseModel;

/**
 * 供求列表模型
 */
class supplyDemand extends BaseModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'sd_id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_supply_demand';
    protected $append=[
        'product_category_text',
        'supply_demand_text',
        'enterprise_id_text'

    ];
    
    /**
     * 商品名称 搜索
     */
    public function searchProductNameAttr($query, $value)
    {
        $query->where('product_name', 'like', '%'.$value.'%');
    }
    
    /**
     * 商品副标题 搜索
     */
    public function searchProductSubtitleAttr($query, $value)
    {
        $query->where('product_subtitle', 'like', '%'.$value.'%');
    }

    public function getProductCategoryTextAttr($value,$data){
       
        if(isset($data['product_category'])){
            return    ClassificationDictionary::where('dictionary_id', $data['product_category'])->value('classification_name_zh');
        }
        return '';
    }
    public function getSupplyDemandTextAttr($value,$data){
       
        if(isset($data['supply_demand'])){
            return    ClassificationDictionary::where('dictionary_id', $data['supply_demand'])->value('classification_name_zh');
        }
        return '';
    }
    public function getEnterpriseIdTextAttr($value,$data){
       
        if(isset($data['enterprise_id'])){
            return    enterpriseContact::where('contact_id', $data['enterprise_id'])->value('enterprise_name');
        }
        return '';
    }



}
